﻿using UnityEngine;
using System.Collections;

public class build_Enemy : MonoBehaviour {

	//生成敌人的时间间隔
	float m_time =3;
	float state =0;
	//敌人种类
	float leibie = 4.5f;
	//生成xiao_BOSS1的时间间隔
	float xiao_time = 5;
	//是否开始计算小BOSS1的生成时间
	bool xiaoboss_bool = false;
	Quaternion ang = Quaternion.identity;
	Transform m_transform;
	void Start () {
	
		m_transform = this.transform;Instantiate(Resources.Load<GameObject>(SampleXml.prefabPath[23].ToString()),new Vector3(-Random.Range(2,374)/100,7.58F,0),Quaternion.identity);
		ang.eulerAngles = new Vector3(0,0,180);
	}
	

	void Update () {
	
		m_time-=Time.deltaTime;

		if(m_time<=0)
		{
			state = Random.value*leibie;
		   this.build(state);
		}

		//生成xiao_BOSS1的时间
		if(xiaoboss_bool)
		{
		  xiao_time-=Time.deltaTime;
		  if(xiao_time<=0)
		  { 
			leibie = 4.5f;
			xiao_time =5;
			xiaoboss_bool  =false;
		  }
		}
	}
	//生成敌人
	void build(float state)
	{
		//enemy1 机群
		if(state>=0&&state<=2)
		{
			Instantiate(Resources.Load<GameObject>(SampleXml.prefabPath[23].ToString()),new Vector3(-Random.Range(2,374)/100,7.58F,0),Quaternion.identity);
		//enemy2 机群
		}else if(state>2&&state<=4)
		{
			Instantiate(Resources.Load<GameObject>(SampleXml.prefabPath[24].ToString()),new Vector3(Random.value*2.6f,-0.42F,0),ang);
		//xiao_BOSS1 机群
		}else if(state>4)
		{
			Instantiate(Resources.Load<GameObject>(SampleXml.prefabPath[25].ToString()));
			leibie = 4;
			xiaoboss_bool = true;
		}
		m_time =Random.Range(3,4);
	}
}
